package org.iweb.html.impl.widget;

import org.iweb.html.api.AbstractWidget;
import org.iweb.html.api.JFunction;
import org.iweb.html.impl.js.State;
import org.iweb.html.impl.session.MainManager;

public class Dialog extends AbstractWidget {

	private static final long serialVersionUID = 8153842961978481555L;
	public final static String FOLD_MODE="fold";
	
	public Dialog setModal(Boolean modal){
		getScriptAttribute().put("modal", ""+modal);
		refreshScript();
		return this;
	}
	
	public Dialog setOpenMode(String openMode){
		getScriptAttribute().put("show", "\""+openMode+"\"");
		refreshScript();
		return this;
	}
	
	public Dialog setCloseMode(String closeMode){		
		getScriptAttribute().put("hide", "\""+closeMode+"\"");
		refreshScript();
		return this;
	}
	
	
	public JFunction open(){
		
		MainManager.getAppSession().getAppState().getHtmlState().addState(getId(), new State("open",""));
		
		return new JFunction("$(\"#"+getId()+"\").dialog(\"open\");");
	}
	
	public JFunction close(){
		return new JFunction("$(\"#"+getId()+"\").dialog(\"close\");");
	}

	public Dialog setAutoOpen(Boolean autoOpen) {
		getScriptAttribute().put("autoOpen", ""+autoOpen);
		refreshScript();
		return this;
	}
	
	@Override
	public String getScriptTag() {
		return "modal";
	}
}
